/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pneuservis.backend.services.impl;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import org.apache.shiro.authz.annotation.RequiresRoles;
import pneuservis.backend.dao.ServicePneuDAOLocal;
import pneuservis.backend.entities.ServicePneu;
import pneuservis.backend.others.Secured;
import pneuservis.backend.services.ServicePneuServiceLocal;
import pneuservis.backend.to.ServicePneuTO;


/**
 *
 * @author Lukas Valkovic
 */
@Stateless(name="ServicePneuService", mappedName="ServicePneuService")
@TransactionManagement(TransactionManagementType.CONTAINER)
public class ServicePneuService implements ServicePneuServiceLocal {
       
    @EJB
    private ServicePneuDAOLocal servicePneuDAO;
    
        
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    @Override
    @Secured
    @RequiresRoles("admin")
    public void createService(ServicePneuTO servicePneu) {
        servicePneuDAO.createService(servicePneu.toServicePneu());

    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    @Override
    public ServicePneuTO getService(Long id) {
        return new ServicePneuTO(servicePneuDAO.getService(id));
    }
    
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    @Override
    @Secured
    @RequiresRoles("admin")
    public void updateService(ServicePneuTO servicePneu) {
        servicePneuDAO.updateService(servicePneu.toServicePneu());
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    @Override
    @Secured
    @RequiresRoles("admin")
    public void removeService(ServicePneuTO servicePneu) {
        servicePneuDAO.removeService(servicePneu.toServicePneu());
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    @Override
    public List<ServicePneuTO> getAllServices() {
        List<ServicePneuTO> result = new ArrayList<ServicePneuTO>();
        for (ServicePneu s : servicePneuDAO.getAllServices()) {
            result.add(new ServicePneuTO(s));
        }
        return result;
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    @Override
    public List<ServicePneuTO> findServiceWithName(String name) {
        List<ServicePneuTO> result = new ArrayList<ServicePneuTO>();
        for (ServicePneu s : servicePneuDAO.findServiceWithName(name)) {
            result.add(new ServicePneuTO(s));
        }
        return result;
    }
}